package com.cpkso.taobao.taobao11client;

import java.awt.BorderLayout;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigInteger;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import com.teamdev.jxbrowser.chromium.az;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

/**
 * 淘宝订单统计客户端
 *
 */
public class App {
	
	static {
	    try {
	        Field e = az.class.getDeclaredField("e");
	        e.setAccessible(true);
	        Field f = az.class.getDeclaredField("f");
	        f.setAccessible(true);
	        Field modifersField = Field.class.getDeclaredField("modifiers");
	        modifersField.setAccessible(true);
	        modifersField.setInt(e, e.getModifiers() & ~Modifier.FINAL);
	        modifersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
	        e.set(null, new BigInteger("1"));
	        f.set(null, new BigInteger("1"));
	        modifersField.setAccessible(false);
	    } catch (Exception e1) {
	        e1.printStackTrace();
	    }
	}
	
    public static void main( String[] args ) {
System.out.println("已启动");
		String username = null;
		String path = null;
		if (args.length > 1) {
			System.out.println(args[0]);
			username = args[0];
			path = args[1];
		} else {
			username = "q";
			path = "D:/";
		}
    	SellerClient.seller(username, path);
    	BuyerClient.buyer(username);
    }

	public static void initalFrame(BrowserView view, final JButton generateOrder, String title) {
        JPanel confirm = new JPanel(new BorderLayout());
        
        // 设置获取订单的时间
        // 请输入用户名
//        final JTextField usernameBar = new JTextField();
        generateOrder.setText("登录后点击按钮获取本月订单");
        confirm.add(generateOrder, BorderLayout.CENTER);
//        confirm.add(usernameBar, BorderLayout.EAST);
        // 创建客户端
        JFrame frame = new JFrame(title);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.add(confirm, BorderLayout.NORTH);
        frame.setSize(1080, 800);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
	}

	public static void sleep() {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
}
